package com.example.smoke;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.vcn.VcnCellUnderlyingNetworkTemplate;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.yalantis.ucrop.UCrop;

import java.time.Instant;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    //声明控件
    private Button mBtnLogin;
    private EditText mEtUser;
    private EditText mEtPassword;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //找到控件
        mBtnLogin = findViewById(R.id.btn_login);
        mEtUser = findViewById(R.id.et_1);
        mEtPassword = findViewById(R.id.et_2);


        //匹配正确的用户名和密码后跳转
        mBtnLogin.setOnClickListener(this);
    }

    public void onClick(View v){
        //获取输入的用户名和密码
        String username = mEtUser.getText().toString();
        String  password = mEtPassword.getText().toString();
        //弹出内容
        String ok = "登录成功！";
        String fail = "用户名或密码错误，请重新登录！";

        Intent intent = null;

        //账号密码分别为 admin,admin123
        if(username.equals("admin")&&password.equals("admin123")){
            //toast底部显示登录成功
            Toast.makeText(getApplicationContext(),ok,Toast.LENGTH_SHORT).show();

            //如果正确则跳转
            intent = new Intent(MainActivity.this,FunctionActivity.class);
            startActivity(intent);
        }else{
            //不正确居中弹出登录失败
            Toast toastCenter = Toast.makeText(getApplicationContext(),fail,Toast.LENGTH_SHORT);
            toastCenter.setGravity(Gravity.CENTER,0,0);
            toastCenter.show();
        }

    }

}